<?php
require_once('calendarSyncCommon.php');
CalendarSyncUtil::debug("Session", $_SESSION);
if(isset($_GET['logout'])){
    $_SESSION = array();
    header("Location: main.php");
}
$client = new apiClient();
$client->setApplicationName("Google Calendar Sync");

$calender_id="";
$cal = new apiCalendarService($client);

if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
}
?>
<html>
    <body>
        <h1>Event Sync Menu</h1>
        <?php if(!isset($_SESSION['user_id'])){ ?>
            <a href="sfdcLogin.php?continue=true">Please login to salesforce first</a>
        <?php } else if ($client->getAccessToken()) {
//                        $calendar = $cal->calendars->get("primary");// Get Primary Calender 
//                        $calender_id = $calendar->getId();//Set ID of primary Calender
//                        $_SESSION['calender_id'] = $calender_id;
//                        $_SESSION['token'] = $client->getAccessToken();
                        print "<ul> <li><a class='login' href='test_bootstrap.php'>Run Sync</a></li>";
                        print "<li><a class='login' href='test_sftogoogleupsert.php'>Run Salesforce to Google Sync</a></li>";
                        print "<li><a class='login' href='test_googletosfupsert.php'>Run Google to Salesforce Sync</a></li>";
                        print "<li><a class='login' href='main.php?logout=true'>Logout</a></li></ul>";
                        } else {
                        $authUrl = $client->createAuthUrl();
                        print "<a class='login' href='$authUrl'>Connect Me!</a>";
                        } ?>              
        
    </body>
</html>
